package team.knowers.qzh.qzhserver.controller;

import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import team.knowers.qzh.qzhserver.common.convention.result.Result;
import team.knowers.qzh.qzhserver.common.convention.result.Results;
import team.knowers.qzh.qzhserver.dto.req.ChangeProgressReqDTO;
import team.knowers.qzh.qzhserver.dto.req.SetMyCourseReqDTO;
import team.knowers.qzh.qzhserver.dto.resp.MyCourseRespDTO;
import team.knowers.qzh.qzhserver.service.MyCourseService;

import java.util.List;

/**
 * 我的课程控制层
 *
 * @author xtg
 */
@RestController
@RequiredArgsConstructor
public class MyCourseController {
    private final MyCourseService myCourseService;

    /**
     * 显示我的课程
     */
    @GetMapping("/api/qzh-server/admin/v1/user/my-course/{username}")
    public Result<List<MyCourseRespDTO>> listMyCourse(@PathVariable("username") String username) {
        return Results.success(myCourseService.listMyCourse(username));
    }

    /**
     * 某用户添加某课程学习
     */
    @PostMapping("/api/qzh-server/admin/v1/user/course/setMyCourse")
    public Result<Boolean> setMyCourse(@RequestBody SetMyCourseReqDTO reqDTO) {
        return Results.success(myCourseService.setMyCourse(reqDTO));
    }

    /**
     * 某课程是否被某用户订阅
     */
    @GetMapping("/api/qzh-server/admin/v1/user/course/isMyCourse")
    public Result<Boolean> isMyCourse(SetMyCourseReqDTO reqDTO) {
        return Results.success(myCourseService.isMyCourse(reqDTO));
    }

    /**
     * 更改用户某课程学习进度
     */
    @PostMapping("/api/qzh-server/admin/v1/user/course/changeProgress")
    public Result<Void> changeProgress(@RequestBody ChangeProgressReqDTO reqDTO) {
        return Results.success(myCourseService.changeProgress(reqDTO));
    }

    /**
     * 获取学习进度
     */
    @GetMapping("/api/qzh-server/admin/v1/user/course/progress")
    public Result<Long> getProgress(@RequestParam("courseId") Long courseId, @RequestParam("username") String username) {
        return Results.success(myCourseService.getProgress(courseId, username));
    }
}
